import Vue from 'vue'
import Router from 'vue-router'
import login from '@/components/login/login.vue'
import home from '@/components/home/home.vue'

Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'home',
      component: home
    },
    {
      path: '/login',
      name: 'login',
      component: login
    }
  ]
})
//在路由统一生效之前统一判断token
//路由守卫，导航守卫
// router.beforeEach((to,from,next) => {
//   console.log(to,from)
//   if(to.path === '/login'){
//     next()
//   }else{
//     const token = localStorage.getItem('token')
//     if (!token){
//       router.push({
//         name: 'login'
//       })
//       return
//     }
//     next()
//   }  
// })
export default router
